﻿using Coolzon.UI.Core.Parts;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using RT = Coolzon.Metadata.Runtime;

namespace Coolzon.UI.Core
{
    public static class PartFactory
    {
        public static IComponent CreatePart(string typeName, string name)
        {
            IComponent part = null;
            if (string.Equals("SCENE", typeName, StringComparison.CurrentCultureIgnoreCase))
            {
                part = new Scene();
                (part as Scene).Name = name;
            }
            else if (string.Equals("Area", typeName, StringComparison.CurrentCultureIgnoreCase))
            {
                part = new Area();
                (part as Area).Name = name;
            }
            else
            {
                foreach (var key in PartLibraryManager.PartTypeDict.Keys)
                {
                    if (string.Equals(key, typeName, StringComparison.CurrentCultureIgnoreCase))
                    {
                        part = (Widget)PartLibraryManager.PartTypeDict[key].Assembly.CreateInstance(PartLibraryManager.PartTypeDict[key].FullName);
                        (part as Widget).Name = name;
                    }
                }
            }

            part.XFullName = name;
            return part;
        }
    }
}
